import { NotFoundError, t } from 'elysia'
import { ElysiaApp } from '../index'
import crypto from 'crypto'

import { table } from '../schema/schema'
import { like, ne, and, count, eq, or } from 'drizzle-orm'
import { isUndefined } from 'lodash'


export default (app: ElysiaApp) =>
  app.get(
    '/blog/list',
    async ({ db, query }) => {
      const { page = 1, pageSize = 10, name, phone } = query
      let blogList = await db.select().from(table.blog)
      return { blogList, page, pageSize, name, phone }
    },
    {
      query: t.Object({
        page: t.Optional(t.Numeric()),
        pageSize: t.Optional(t.Numeric()),
        name: t.Optional(t.String()),
        phone: t.Optional(t.String()),
      }),
    },
  ).get('/blog/add', async ({ db, query }) => {
    let u = await db.select().from(table.user).limit(1)
    if (u.length > 0) {
      let ff = db.insert(table.blog).values({ userId: u[0].id, content: "据悉，吃饭得用嘴", });
      ff.execute()
      return { flag: '找到了一个用户，为它添加一个博客' }
    } else {
      return { flag: '没有找到用户，未添加博客' }
     }
      
     
    })


